home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / jrh-rkrm-partone / workbench / prargs.e < prev   
Text File  |  1995-03-30  |  2KB  |  56 lines

  1. -> PrArgs.e - This program prints all Workbench or Shell (CLI) arguments.
  2. -> E-Note: ignore all the rubbish (in the C version) about start-ups
  3.  
  4. MODULE 'other/split',
  5.        'workbench/startup'
  6.  
  7. PROC main()
  8.   DEF argmsg:PTR TO wbstartup, wb_arg:PTR TO wbarg, ktr, olddir,
  9.       argv:PTR TO LONG
  10.   -> wbmessage is non-NIL when run from the Workbench, NIL when run from the CLI
  11.   IF wbmessage
  12.     -> E-Note: WriteF opens its own output window, if necessary
  13.     -> wbmessage contains a pointer to the WBStartup message
  14.     argmsg:=wbmessage
  15.     wb_arg:=argmsg.arglist  -> Head of the arg list
  16.  
  17.     WriteF('Run from the Workbench, \d args.\n', argmsg.numargs)
  18.  
  19.     FOR ktr:=0 TO argmsg.numargs-1
  20.       IF wb_arg.lock<>NIL
  21.         -> Locks supported, change to the proper directory
  22.         olddir:=CurrentDir(wb_arg.lock)
  23.  
  24.         -> Process the file.
  25.         -> If you have done the CurrentDir() above, then you can access the file
  26.         -> by its name.  Otherwise, you have to examine the lock to get a
  27.         -> complete path to the file.
  28.         WriteF('\tArg \d[2] (w/ lock): "\s".\n', ktr, wb_arg.name)
  29.  
  30.         -> Change back to the original directory when done.  Be sure to change
  31.         -> back before you exit.
  32.         CurrentDir(olddir)
  33.       ELSE
  34.         -> Something that does not support locks
  35.         WriteF('\tArg \d[2] (no lock): "\s".\n', ktr, wb_arg.name)
  36.       ENDIF
  37.       wb_arg++
  38.     ENDFOR
  39.     -> E-Note: no need to wait: output window closes after a RETURN press
  40.   ELSE
  41.     -> E-Note: WriteF opens its own output window, if necessary
  42.     -> E-Note: argSplit() splits arg into a NIL-terminated E-list, which can be
  43.     ->         used like C's argv (except that the first element of the list is
  44.     ->         the first argument, not the program name...)
  45.     IF argv:=argSplit()
  46.       WriteF('Run from the CLI, \d args.\n', ListLen(argv))
  47.       FOR ktr:=0 TO ListLen(argv)-1
  48.         -> Print an arg, and its number
  49.         WriteF('\tArg \d[2]: "\s".\n', ktr+1, argv[ktr])
  50.       ENDFOR
  51.     ELSE  -> E-Note: argSplit() ran out of memory...
  52.       WriteF('Run from the CLI, arg is "\s".\n', arg)
  53.     ENDIF
  54.   ENDIF
  55. ENDPROC
  56.